﻿using System;
using System.Collections;

namespace ObjectEditor
{
    public class CollectionItem : AbstractValue
    {
        protected object ObjectPointer;
        protected IList Data { get; set; }

        public int Index { get; protected set; }

        public override object Object
        {
            get { return ObjectPointer; }
        }

        public override Type Type { get { return ObjectPointer.GetType(); } }

        public override object Value
        {
            get
            {
                return ObjectPointer;
            }
            set
            {
                ObjectPointer = value;
                Data[Index] = value;
            }
        }

        public CollectionItem(object objectPointer, IList data, int index)
        {
            ObjectPointer = objectPointer;
            Data = data;
            Index = index;
        }

        public override string ToString()
        {
            return ObjectPointer.ToString();
        }
    }
}
